package cn.com.twoke.easyproject.aspect.request.lock.hook.after;

import cn.com.twoke.easyproject.aspect.request.lock.RequestLock;
import cn.com.twoke.easyproject.common.context.holder.UserLoginContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;

/**
 * 给生成的请求锁添加用户信息
 */
@Slf4j
public class GenerateKeyAfterWithUser implements GenerateKeyHook {

    /**
     * 如果需要检查用户信息，那么添加用户信息到请求锁中
     * @param key
     * @param joinPoint
     * @param requestLock
     * @return
     */
    @Override
    public String doAfter(String key, ProceedingJoinPoint joinPoint, RequestLock requestLock) {
        if (requestLock.checkUser()) {
            return  requestLock.delimiter() + "uid=" + UserLoginContextHolder.get().getUid() + key;
        }
        return key;
    }

}
